package com.wh;

import java.util.Stack;

public class DuiLie {
    private Stack<Integer> stack1 = new Stack<>();
    private Stack<Integer> stack2 = new Stack<>();

    public Integer push(int i) {
        return stack1.push(i);
    }

    public Integer pop() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    public static void main(String[] args) {
        DuiLie duiLie = new DuiLie();
        duiLie.push(5);
        duiLie.push(1);
        duiLie.push(8);
        System.out.println(duiLie.pop());
        System.out.println(duiLie.pop());
        System.out.println(duiLie.pop());
    }
}
